package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class MakeFriendController {

   @Autowired
   private MakeFriendManager makeFriendManager;

   //今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest(){
        //调用manager
        return makeFriendManager.findTodayBest();
    }

    // 推荐用户
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserVoByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ){
        //调用manager
        return makeFriendManager.findReommendUserVoByPage(pageNum,pageSize);
    }


    // 推荐用户详情
    @GetMapping("/tanhua/{jiarenId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long jiarenId){
        // 调用manager
        return makeFriendManager.findPersonalInfo(jiarenId);
    }

    //最近访客
    @GetMapping("/movements/visitores")
    public ResponseEntity findVisitors(){
        // 调用manager
        return makeFriendManager.findVisitors();
    }

    //上报地理位置
    @PostMapping("/baidu/location")
    public void saveLocation(@RequestBody Map<String,String> param){
        System.out.println("上报地理位置:"+param);
        //1.接收参数
        Double longitude = Double.parseDouble(param.get("longitude"));
        Double latitude = Double.parseDouble(param.get("latitude"));
        String addStr = param.get("addStr");
        //2. 调用manager
        makeFriendManager.saveLocation(longitude,latitude,addStr);
    }

    //搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchnearUser(String gender,Long distance){
        //调用manager
        return makeFriendManager.searchNearUser(gender,distance);
    }

    // 聊一下(查看陌生人问题)
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity strangrQuestions(@RequestParam("userId") Long jarenId){
        //调用manager
        return makeFriendManager.strangerQuestions(jarenId);
    }
}
